package learn.socket_01;

import java.io.*;
import java.net.Socket;

/**
 * @author ZhangQi
 */
public class TimeClient_01 {
    public static void main(String[] args) {
        int port = 9929;
        Socket socket=null;
        BufferedReader in=null;
        PrintWriter out=null;
        try{
            socket=new Socket("127.0.0.1",port);
            in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out=new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);
            out.println("now");
            String read1=in.readLine();
            System.err.println(read1);
            out.println("qwe");
            System.err.println(in.readLine());
        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            if(in!=null){
                try {
                    in.close();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
            if(out!=null){
                out.close();
            }
            if(socket!=null){
                try {
                    socket.close();
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }
            socket=null;
        }
    }
}

